﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TiTi.tea.Api.Models;
using TiTi.tea.BLL;
using TiTi.tea.Model;

namespace TiTi.tea.Api.Controllers
{
    
    [RoutePrefix("api/dictType")]
    public class DictTypeController : ApiController
    {

        private DictTypeBLL bll=new DictTypeBLL();

        [Route("Query")]
        [HttpGet]
        public Result Query(string DictTypeName,int PageSize,int PageIndex) 
        {
            int total = 0;
            var data = bll.Query(DictTypeName,out  total,PageSize,PageIndex);
            return Result.Success(new { data,total});
        }

        public Result Get(int id) 
        {
            var data = bll.Get(id);
            return Result.Success(data);
        }
        [Route("Add")]
        [HttpPost]
        public Result Add(DictType entity) 
        {
        entity.CreateTime = DateTime.Now;
            entity.IsDelete = 0;
            if (bll.Add(entity))
            {
                return Result.Success(entity);
            }
            else 
            {
                return Result.Error("添加失败");
            }
        }

        public Result Update(DictType entity) 
        {
            DictType dicttype = bll.Get(entity.Id);
            dicttype.DictTypeName=entity.DictTypeName;

            if (bll.Update(dicttype))
            {
                return Result.Success(dicttype);
            }
            else 
            {
                return Result.Error("修改失败");
            }
        }
        public Result Delete(int id) 
        {
            return Result.Success(bll.Delete(id));
        }
    }
}
